package org.supda.system.util;

import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class ApplicationContextUtil {
	private static ApplicationContext applicationContext = null;
	
	private  ApplicationContextUtil( ServletContext context){
		applicationContext = WebApplicationContextUtils.getWebApplicationContext(context);
	}
	
	public static void getInstance(ServletContext context){
		if(applicationContext==null)
			new ApplicationContextUtil(context);
	}
	/**
	 * 获取bean实例
	 * @param bean
	 * @return
	 */
	public static Object getBean(String bean){
		return applicationContext.getBean(bean);
	}

	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	public static void setApplicationContext(ApplicationContext applicationContext) {
		ApplicationContextUtil.applicationContext = applicationContext;
	}
}
